home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / MyConnecti2048092162007.psc / Class Modules / MyConnection.cls next >
Text File  |  2007-02-16  |  42KB  |  1,135 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "MyConnection"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. 'Written by Mehmet Gⁿrevin :)
  15.  
  16. Option Explicit
  17.  
  18. Public Enum BATHPROGRESSTYPE
  19.     MEMORY_PROGRESS
  20.     FILE_PROGRESS
  21.     RESOURCE_PROGRESS
  22. End Enum
  23.  
  24. Public Enum MYSTATE
  25.     MY_CONNECTED
  26.     MY_NOT_CONNECTED
  27. End Enum
  28.  
  29. Private Const SIZE_OF_CHAR = 4
  30.  
  31. Private Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  32. Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
  33.  
  34. Private Declare Function CreateReadFileHandle Lib "kernel32.dll" Alias "CreateFileA" ( _
  35.                          ByVal lpFileName As String, _
  36.                          Optional ByVal dwDesiredAccess As Long = &H80000000, _
  37.                          Optional ByVal dwShareMode As Long = &H1, _
  38.                          Optional ByVal lpSecurityAttributes As Long = 0&, _
  39.                          Optional ByVal dwCreationDisposition As Long = 3, _
  40.                          Optional ByVal dwFlagsAndAttributes As Long = 0&, _
  41.                          Optional ByVal hTemplateFile As Long = 0&) As Long
  42. Private Declare Function CreateWriteFileHandle Lib "kernel32" Alias "CreateFileA" ( _
  43.                          ByVal lpFileName As String, _
  44.                          Optional ByVal dwDesiredAccess As Long = &H2, _
  45.                          Optional ByVal dwShareMode As Long = &H2, _
  46.                          Optional ByVal lpSecurityAttributes As Long = 0, _
  47.                          Optional ByVal dwCreationDisposition As Long = 2, _
  48.                          Optional ByVal dwFlagsAndAttributes As Long = 0, _
  49.                          Optional ByVal hTemplateFile As Long = 0) As Long
  50. Private Declare Function APIWriteFile Lib "kernel32" Alias "WriteFile" ( _
  51.                          ByVal hFile As Long, _
  52.                          ByVal lStringPointer As Long, _
  53.                          ByVal lStringLength As Long, _
  54.                          ByRef ReturnToWriteNumberOfBytes As Long, _
  55.                          Optional ByVal DO_NOT_USE As Long = 0) As Long
  56. Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, _
  57.                          ByRef lpBuffer As Any, _
  58.                          ByVal nNumberOfBytesToRead As Long, _
  59.                          ByRef lpNumberOfBytesRead As Long, _
  60.                          ByVal lpOverlapped As Any) As Long
  61. Private Declare Function GetFileSize Lib "kernel32.dll" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  62. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  63. Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long
  64.  
  65. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
  66.  
  67. Private Declare Function lstrcmpi Lib "kernel32.dll" Alias "lstrcmpiA" (ByVal lpString1 As Long, ByVal lpString2 As String) As Long
  68. Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long
  69.  
  70. Private Declare Function mysql_init Lib "libmysql.dll" (ByVal hMysql As Long) As Long
  71.  
  72. Private Declare Function mysql_real_connect Lib "libmysql.dll" (ByVal hMysql As Long, ByVal Host As Long, ByVal User As Long, ByVal Passwd As Long, ByVal dB As Long, ByVal Port As Long, ByVal Unix_Socket As Long, ByVal clientflag As Long) As Long
  73. Private Declare Function mysql_close Lib "libmysql.dll" (ByVal hMysql As Long) As Long
  74.  
  75. Private Declare Function mysql_errno Lib "libmysql.dll" (ByVal hMysql As Long) As Long
  76. Private Declare Function mysql_error Lib "libmysql.dll" (ByVal hMysql As Long) As Long
  77.  
  78. Private Declare Function mysql_select_db Lib "libmysql.dll" (ByVal hMysql As Long, ByVal dB As Long) As Long
  79. Private Declare Function mysql_options Lib "libmysql.dll" (ByVal hMysql As Long, ByVal PropID As Long, ByVal arg As Long) As Long
  80.  
  81. Private Declare Function mysql_real_query Lib "libmysql.dll" (ByVal hMysql As Long, ByVal q As Long, ByVal Length As Long) As Long
  82. Private Declare Function mysql_send_query Lib "libmysql.dll" (ByVal hMysql As Long, ByVal q As Long, ByVal Length As Long) As Long
  83. Private Declare Function mysql_escape_string Lib "libmysql.dll" (ByVal to_ As String, ByVal from_ As String, ByVal Length As Long) As Long
  84.  
  85. Private Declare Function mysql_store_result Lib "libmysql.dll" (ByVal hMysql As Long) As Long
  86. Private Declare Function mysql_free_result Lib "libmysql.dll" (ByVal lResultPointer As Long) As Long
  87.  
  88. Private Declare Function mysql_field_count Lib "libmysql.dll" (ByVal hMysql As Long) As Long
  89. Private Declare Function mysql_fetch_field Lib "libmysql.dll" (ByVal lResultPointer As Long) As Long                                            'Return the field struct pointer
  90. Private Declare Function mysql_num_rows Lib "libmysql.dll" (ByVal lResultPointer As Long) As Long                                               'Return the 8 bit lenght pointer, myulonglong
  91. Private Declare Function mysql_fetch_row Lib "libmysql.dll" (ByVal lResultPointer As Long) As Long                                              'Return the row struct pointer
  92.  
  93. Private Declare Function mysql_get_server_info Lib "libmysql.dll" (ByVal hMysql As Long) As Long
  94. Private Declare Function mysql_stat Lib "libmysql.dll" (ByVal hMysql As Long) As Long
  95.  
  96. Private Declare Function mysql_list_dbs Lib "libmysql.dll" (ByVal hMysql As Long, ByVal wild As Long) As Long                                                 'Return the True or False
  97. Private Declare Function mysql_list_tables Lib "libmysql.dll" (ByVal hMysql As Long, ByVal wild As Long) As Long                                                 'Return the True or False
  98. Private Declare Function mysql_list_fields Lib "libmysql.dll" (ByVal hMysql As Long, ByVal table As Long, ByVal wild As Long) As Long                                                'Return the True or False
  99. Private Declare Function mysql_fetch_lengths Lib "libmysql.dll" (ByVal lResultPointer As Long) As Long                              'returns * unsigned long
  100.  
  101. Private Declare Function GetSystemDirectoryA Lib "kernel32.dll" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  102. Private Declare Function GetShortPathNameA Lib "kernel32.dll" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
  103. Private Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
  104.  
  105. Public Event Connected(ByVal lAPIHandle As Long, _
  106.                        ByVal sHost As String, _
  107.                        ByVal sUser As String, _
  108.                        ByVal sPass As String, _
  109.                        ByVal sDatabase As String, _
  110.                        ByVal lPort As String, _
  111.                        ByVal sUnixSocket As String)
  112.                        
  113. Public Event Disconnected(ByVal lAPIHandle As Long, _
  114.                           ByVal sHost As String)
  115.                           
  116. Public Event BatchQueryProgress(ByVal lTotal As Long, _
  117.                                 ByVal lCurrent As Long, _
  118.                                 ByVal eProgressType As BATHPROGRESSTYPE)
  119.                                 
  120. Public Event OnError(ByVal ErrCode As Long, ByVal ErrDescription As String)
  121.  
  122. Private lRet                                    As Long
  123. Private bRet                                    As Boolean
  124.  
  125. Private APIHandle                               As Long
  126. Private lResult                                 As Long
  127.  
  128. Private IsConnected                             As Boolean
  129. Private OpenIsReader                            As Boolean
  130.  
  131. Private i                                       As Long
  132. Private j                                       As Long
  133.  
  134. Private mUsername                               As String
  135. Private mPassword                               As String
  136. Private mServerAddress                          As String
  137. Private mServerPort                             As Long
  138. Private mDatabaseName                           As String
  139. Private mUnixSocket                             As String
  140. Private mConnectionTimeout                      As Long
  141. Private mCharset                                As String
  142. Private mGiveError                              As Boolean
  143.  
  144. Public Property Get State() As MYSTATE
  145.     If (IsConnected) Then
  146.         State = MY_CONNECTED
  147.     Else
  148.         State = MY_NOT_CONNECTED
  149.     End If
  150. End Property
  151.  
  152. Public Property Get ObjectPointer() As Long
  153.     ObjectPointer = ObjPtr(Me)
  154. End Property
  155.  
  156. Public Property Get GiveError() As Boolean
  157.     GiveError = mGiveError
  158. End Property
  159.  
  160. Public Property Let GiveError(ByVal Value As Boolean)
  161.     mGiveError = Value
  162. End Property
  163.  
  164. Public Property Get ConnectionHandle() As Long
  165.     ConnectionHandle = APIHandle
  166. End Property
  167.  
  168. Public Property Let ConnectionHandle(ByVal Value As Long)
  169.     APIHandle = Value
  170.     IsConnected = True
  171. End Property
  172.  
  173. Public Property Get ConnectionTimeout() As Long
  174.     ConnectionTimeout = mConnectionTimeout
  175. End Property
  176.  
  177. Public Property Let ConnectionTimeout(ByVal Value As Long)
  178.     If Not (IsConnected) Then
  179.         mConnectionTimeout = Value
  180.         lRet = mysql_options(APIHandle, 0, StrPtr(StrConv(CStr(Value), vbFromUnicode)))
  181.         If lRet <> 0 Then
  182.             If (mGiveError) Then
  183.                 Err.Raise vbObjectError + GetErrorCode, GetErrorCode & ":" & GetErrorDescription
  184.             Else
  185.                 RaiseErrorEvent
  186.             End If
  187.         End If
  188.     Else
  189.         If (mGiveError) Then
  190.             Err.Raise vbObjectError - 4, , "-4:" & " Aktif ba≡lant² var. ╓ncelikle aktif ba≡lant²y² kapatman²z gerekir."
  191.         Else
  192.             RaiseErrorEvent -4
  193.         End If
  194.     End If
  195. End Property
  196.  
  197. Public Property Get Username() As String
  198.     Username = mUsername
  199. End Property
  200.  
  201. Public Property Let Username(ByVal Value As String)
  202.     If Not (IsConnected) Then
  203.         If (Len(Trim(Value)) = 0) Then Value = "root"
  204.         mUsername = Value
  205.     Else
  206.         If (mGiveError) Then
  207.             Err.Raise vbObjectError - 4, , "-4: Aktif ba≡lant² var. ╓ncelikle aktif ba≡lant²y² kapatman²z gerekir."
  208.         Else
  209.             RaiseErrorEvent -4
  210.         End If
  211.     End If
  212. End Property
  213.  
  214. Public Property Get Charset() As String
  215.     Charset = mCharset
  216. End Property
  217.  
  218. Public Property Let Charset(ByVal Value As String)
  219.     If (IsConnected) Then
  220.         If (CLng(Left(Ptr2Str(mysql_get_server_info(APIHandle)), 1)) < 5) Then
  221.             If (GiveError) Then
  222.                 'Err.Raise vbObjectError - 5, , "-5: Veritaban² sunucu versiyonu 5.0'dan dⁿ■ⁿk oldu≡u iτin 'SET NAMES' komutu i■letilemiyor. Lⁿtfen sunucu versiyonunuzu gⁿncelleyiniz"
  223.                 Call MsgBox("MySQL server version required 5.0 or higher.")
  224.             Else
  225.                 RaiseErrorEvent -5
  226.             End If
  227.         Else
  228.             If (Len(Trim(Value))) Then
  229.                 mCharset = Value
  230.                 lRet = mysql_send_query(APIHandle, StrPtr(StrConv("SET NAMES '" & mCharset & "'", vbFromUnicode)), Len("SET NAMES '" & mCharset & "'"))
  231.                 If lRet = 0 Then
  232.                     If (GiveError) Then
  233.                         Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  234.                     Else
  235.                         RaiseErrorEvent
  236.                     End If
  237.                 End If
  238.             End If
  239.         End If
  240.     Else
  241.         If (Len(Trim(Value))) Then
  242.             mCharset = Value
  243.         End If
  244.     End If
  245. End Property
  246.  
  247. Public Property Get Password() As String
  248.     Password = mPassword
  249. End Property
  250.  
  251. Public Property Let Password(ByVal Value As String)
  252.     If Not (IsConnected) Then
  253.         mPassword = Value
  254.     Else
  255.         If (mGiveError) Then
  256.             Err.Raise vbObjectError - 4, , "-4:" & " Aktif ba≡lant² var. ╓ncelikle aktif ba≡lant²y² kapatman²z gerekir."
  257.         Else
  258.             RaiseErrorEvent -4
  259.         End If
  260.     End If
  261. End Property
  262.  
  263. Public Property Get ServerAddress() As String
  264.     ServerAddress = mServerAddress
  265. End Property
  266.  
  267. Public Property Let ServerAddress(ByVal Value As String)
  268.     If Not (IsConnected) Then
  269.         If (Len(Trim(Value)) = 0) Then Value = "localhost"
  270.         mServerAddress = Value
  271.     Else
  272.         If (mGiveError) Then
  273.             Err.Raise vbObjectError - 4, , "-4:" & " Aktif ba≡lant² var. ╓ncelikle aktif ba≡lant²y² kapatman²z gerekir."
  274.         Else
  275.             RaiseErrorEvent -4
  276.         End If
  277.     End If
  278. End Property
  279.  
  280. Public Property Get ServerPort() As Long
  281.     ServerPort = mServerPort
  282. End Property
  283.  
  284. Public Property Let ServerPort(ByVal Value As Long)
  285.     If Not (IsConnected) Then
  286.         If (Value = 0) Then Value = 3306
  287.         mServerPort = Value
  288.     Else
  289.         If (mGiveError) Then
  290.             Err.Raise vbObjectError - 4, , "-4:" & " Aktif ba≡lant² var. ╓ncelikle aktif ba≡lant²y² kapatman²z gerekir."
  291.         Else
  292.             RaiseErrorEvent -4
  293.         End If
  294.     End If
  295. End Property
  296.  
  297. Public Property Get DatabaseName() As String
  298.     DatabaseName = mDatabaseName
  299. End Property
  300.  
  301. Public Property Let DatabaseName(ByVal Value As String)
  302.     If Not (IsConnected) Then
  303.         mDatabaseName = Value
  304.     Else
  305.         lRet = mysql_select_db(APIHandle, StrPtr(StrConv(Value, vbFromUnicode)))
  306.         If lRet <> 0 Then
  307.             If (GiveError) Then
  308.                 Err.Raise vbObjectError + GetErrorCode, GetErrorCode & ": " & GetErrorDescription
  309.             Else
  310.                 RaiseErrorEvent
  311.             End If
  312.         End If
  313.     End If
  314. End Property
  315.  
  316. Public Property Get UnixSocket() As String
  317.     UnixSocket = mUnixSocket
  318. End Property
  319.  
  320. Public Property Let UnixSocket(ByVal Value As String)
  321.     If Not (IsConnected) Then
  322.         If (Value = 0) Then Value = 3306
  323.         mUnixSocket = Value
  324.     Else
  325.         If (mGiveError) Then
  326.             Err.Raise vbObjectError - 4, , "-4:" & " Aktif ba≡lant² var. ╓ncelikle aktif ba≡lant²y² kapatman²z gerekir."
  327.         Else
  328.             RaiseErrorEvent -4
  329.         End If
  330.     End If
  331. End Property
  332.  
  333. Public Function Connect(Optional ByVal sServerAddress As String = vbNullString, _
  334.                         Optional ByVal sUsername As String = vbNullString, _
  335.                         Optional ByVal sPassword As String = vbNullString, _
  336.                         Optional ByVal sDatabase As String = vbNullString, _
  337.                         Optional ByVal lServerPort As Long = -1, _
  338.                         Optional ByVal sUnixSocket As String = vbNullString) As Boolean
  339.     
  340.    
  341.     If Not (IsConnected) Then
  342.         APIHandle = mysql_init(APIHandle)
  343.         If APIHandle = 0 Then
  344.             If (GiveError) Then
  345.                 Err.Raise vbObjectError - 1, , "-1: MySQL API Arabirimi ba■lat²lamad²."
  346.             Else
  347.                 RaiseErrorEvent -1
  348.             End If
  349.             Exit Function
  350.         End If
  351.         
  352.         If Len(Trim(sServerAddress)) > 0 Then mServerAddress = sServerAddress
  353.         If Len(Trim(sUsername)) > 0 Then mUsername = sUsername
  354.         If Len(Trim(sPassword)) > 0 Then mPassword = sPassword
  355.         If Len(Trim(sDatabase)) > 0 Then mDatabaseName = sDatabase
  356.         If lServerPort > 0 Then mServerPort = lServerPort
  357.         If Len(Trim(sUnixSocket)) > 0 Then mUnixSocket = sUnixSocket
  358.         
  359.         lRet = mysql_real_connect(APIHandle, _
  360.                                   StrPtr(StrConv(mServerAddress, vbFromUnicode)), _
  361.                                   StrPtr(StrConv(mUsername, vbFromUnicode)), _
  362.                                   StrPtr(StrConv(mPassword, vbFromUnicode)), _
  363.                                   StrPtr(StrConv(mDatabaseName, vbFromUnicode)), _
  364.                                   mServerPort, _
  365.                                   StrPtr(StrConv(mUnixSocket, vbFromUnicode)), _
  366.                                   0)
  367.  
  368.         If (lRet <> 0) Then
  369.             Connect = True
  370.             IsConnected = True
  371. 'Automatic Setting: Turkish Charset
  372. '            If CLng(Left(Ptr2Str(mysql_get_server_info(APIHandle)), 1)) < 5 Then
  373. '                If (GiveError) Then
  374. '                    Err.Raise vbObjectError - 5, , "-5: Veritaban² sunucu versiyonu 5.0'dan dⁿ■ⁿk oldu≡u iτin 'SET NAMES' komutu i■letilemiyor. Lⁿtfen sunucu versiyonunuzu gⁿncelleyiniz."
  375. '                Else
  376. '                    RaiseErrorEvent -5
  377. '                End If
  378. '            Else
  379. '                lRet = mysql_send_query(APIHandle, StrPtr(StrConv("SET NAMES '" & mCharset & "'", vbFromUnicode)), Len("SET NAMES '" & mCharset & "'"))
  380. '                If lRet <> 0 Then
  381. '                    If (GiveError) Then
  382. '                        Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  383. '                    Else
  384. '                        RaiseErrorEvent
  385. '                    End If
  386. '                End If
  387. '            End If
  388.             
  389.             RaiseEvent Connected(APIHandle, mServerAddress, mUsername, mPassword, mDatabaseName, mServerPort, mUnixSocket)
  390.         Else
  391.             Connect = False
  392.             If (GiveError) Then
  393.                 Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  394.             Else
  395.                 RaiseErrorEvent
  396.             End If
  397.         End If
  398.     Else
  399.         If (mGiveError) Then
  400.             Err.Raise vbObjectError - 4, , "-4:" & " Aktif ba≡lant² var. ╓ncelikle aktif ba≡lant²y² kapatman²z gerekir."
  401.         Else
  402.             RaiseErrorEvent -4
  403.         End If
  404.     End If
  405. End Function
  406.  
  407. Public Property Get GetServerVersion() As String
  408.     If (IsConnected) Then
  409.         GetServerVersion = Ptr2Str(mysql_get_server_info(APIHandle))
  410.     Else
  411.         If (mGiveError) Then
  412.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  413.         Else
  414.             RaiseErrorEvent -3
  415.         End If
  416.     End If
  417. End Property
  418.  
  419. Public Property Get GetServerState() As String
  420.     If (IsConnected) Then
  421.         GetServerState = Ptr2Str(mysql_stat(APIHandle))
  422.     Else
  423.         If (mGiveError) Then
  424.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  425.         Else
  426.             RaiseErrorEvent -3
  427.         End If
  428.     End If
  429. End Property
  430.  
  431. Public Function SelectDatabase(ByVal sDatabaseName As String) As Boolean
  432.     If Len(Trim(sDatabaseName)) = 0 Then Exit Function
  433.     
  434.     If (IsConnected) Then
  435.         lRet = mysql_select_db(APIHandle, StrPtr(StrConv(sDatabaseName, vbFromUnicode)))
  436.         If lRet = 0 Then
  437.             SelectDatabase = True
  438.         Else
  439.             SelectDatabase = False
  440.             If (GiveError) Then
  441.                 Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  442.             Else
  443.                 RaiseErrorEvent
  444.             End If
  445.         End If
  446.     Else
  447.         If (mGiveError) Then
  448.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  449.         Else
  450.             RaiseErrorEvent -3
  451.         End If
  452.     End If
  453. End Function
  454.  
  455. Public Function ExecuteReader(ByVal sQuery As String) As MyReader
  456.     If sQuery = "#closereader#" Then OpenIsReader = False: Exit Function
  457.     
  458.     If Len(Trim(sQuery)) = 0 Then Exit Function
  459.     
  460.     If OpenIsReader Then
  461.         Err.Raise vbObjectError, "MyConnection:ExecuteReader", "Zaten aτ²k bir MyReader nesnesi var."
  462.     End If
  463.     
  464.     Dim lExe                    As Long
  465.     Dim mReader                 As MyReader
  466.     
  467.     lExe = -1
  468.     
  469.     If (IsConnected) Then
  470.         lRet = mysql_real_query(APIHandle, StrPtr(StrConv(sQuery, vbFromUnicode)), Len(sQuery))
  471.         If lRet = 0 Then
  472.             Set ExecuteReader = New MyReader
  473.             OpenIsReader = True
  474.             Set ExecuteReader.CnnObject = Me
  475.             ExecuteReader.ConnectionPointer = APIHandle
  476.             ExecuteReader.ResultPointer = lResult
  477.         Else
  478.             If (GiveError) Then
  479.                 Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  480.             Else
  481.                 RaiseErrorEvent
  482.             End If
  483.         End If
  484.     Else
  485.         If (mGiveError) Then
  486.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  487.         Else
  488.             RaiseErrorEvent -3
  489.         End If
  490.     End If
  491. End Function
  492.  
  493. Public Function Execute(ByVal sQuery As String) As Long
  494.     If Len(Trim(sQuery)) = 0 Then Exit Function
  495.     
  496.     If (IsConnected) Then
  497.         lRet = mysql_real_query(APIHandle, StrPtr(StrConv(sQuery, vbFromUnicode)), Len(sQuery))
  498.         If lRet = 0 Then
  499.             lResult = mysql_store_result(APIHandle)
  500.             If lResult Then
  501.                 Execute = lResult
  502.             End If
  503.         Else
  504.             If (GiveError) Then
  505.                 Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  506.             Else
  507.                 RaiseErrorEvent
  508.             End If
  509.         End If
  510.     Else
  511.         If (mGiveError) Then
  512.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  513.         Else
  514.             RaiseErrorEvent -3
  515.         End If
  516.     End If
  517. End Function
  518.  
  519. Public Function ExecuteNonQuery(ByVal sQuery As String) As Long
  520.     If Len(Trim(sQuery)) = 0 Then Exit Function
  521.     
  522.     If (IsConnected) Then
  523.         lRet = mysql_real_query(APIHandle, StrPtr(StrConv(sQuery, vbFromUnicode)), Len(sQuery))
  524.         If lRet <> 0 Then
  525.             If (GiveError) Then
  526.                 Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  527.             Else
  528.                 RaiseErrorEvent
  529.             End If
  530.             Exit Function
  531.         End If
  532.         ExecuteNonQuery = lRet
  533.     Else
  534.         If (mGiveError) Then
  535.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  536.         Else
  537.             RaiseErrorEvent -3
  538.         End If
  539.     End If
  540. End Function
  541.  
  542. Public Function BathRealQuery(ByVal sBathQuery As String) As Boolean
  543.     If Len(Trim(sBathQuery)) = 0 Then Exit Function
  544.     
  545.     Dim lArray()            As String
  546.     Dim lMax                As Long
  547.     
  548.     If (IsConnected) Then
  549.         lArray = SQLParse(sBathQuery)
  550.         lMax = UBound(lArray)
  551.         
  552.         For i = 0 To UBound(lArray)
  553.             lRet = mysql_real_query(APIHandle, StrPtr(StrConv(lArray(i), vbFromUnicode)), Len(lArray(i)))
  554.             If lRet <> 0 Then
  555.                 If (GiveError) Then
  556.                     Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  557.                 Else
  558.                     RaiseErrorEvent
  559.                 End If
  560.                 Exit Function
  561.             End If
  562.             DoEvents
  563.             RaiseEvent BatchQueryProgress(lMax, i, MEMORY_PROGRESS)
  564.         Next i
  565.         
  566.         BathRealQuery = True
  567.         Erase lArray
  568.     Else
  569.         If (mGiveError) Then
  570.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  571.         Else
  572.             RaiseErrorEvent -3
  573.         End If
  574.     End If
  575. End Function
  576.  
  577. Public Function BathRealQueryFromFile(ByVal sScriptFilePath As String) As Boolean
  578.     If Len(Trim(sScriptFilePath)) = 0 Then Exit Function
  579.     
  580.     Dim hFile               As Long
  581.     Dim fLen                As Long
  582.     Dim fBytes()            As Byte
  583.     Dim lMax                As Long
  584.     
  585.     If Not CBool(PathFileExists(sScriptFilePath)) Then
  586.         If (mGiveError) Then
  587.             Err.Raise vbObjectError - 2, , "-2:" & " Dosya bulunamad²."
  588.         Else
  589.             RaiseErrorEvent -2
  590.         End If
  591.         Exit Function
  592.     End If
  593.     
  594.     hFile = CreateReadFileHandle(sScriptFilePath)
  595.         fLen = GetFileSize(hFile, ByVal 0&)
  596.         ReDim fBytes(fLen) As Byte
  597.     
  598.         ReadFile hFile, fBytes(0), fLen, lRet, ByVal 0&
  599.         sScriptFilePath = StrConv(fBytes, vbUnicode)
  600.     CloseHandle hFile
  601.     Erase fBytes
  602.  
  603.     Dim lArray()            As String
  604.     
  605.     If (IsConnected) Then
  606.         lArray = SQLParse(sScriptFilePath)
  607.         lMax = UBound(lArray)
  608.         
  609.         For i = 0 To UBound(lArray)
  610.             lRet = mysql_real_query(APIHandle, StrPtr(StrConv(lArray(i), vbFromUnicode)), Len(lArray(i)))
  611.             If lRet <> 0 Then
  612.                 If (GiveError) Then
  613.                     Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  614.                 Else
  615.                     RaiseErrorEvent
  616.                 End If
  617.                 Exit Function
  618.             End If
  619.             DoEvents
  620.             RaiseEvent BatchQueryProgress(lMax, i, FILE_PROGRESS)
  621.         Next i
  622.         
  623.         BathRealQueryFromFile = True
  624.         Erase lArray
  625.     Else
  626.         If (mGiveError) Then
  627.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  628.         Else
  629.             RaiseErrorEvent -3
  630.         End If
  631.     End If
  632.     
  633.     sScriptFilePath = Empty
  634. End Function
  635.  
  636. Public Function BathRealQueryFromResource(ByVal lResurceID As Long, Optional ByVal sResurceType As String = "CUSTOM") As Boolean
  637.     Dim sBathQuery          As String
  638.     sBathQuery = StrConv(LoadResData(lResurceID, sResurceType), vbUnicode)
  639.     
  640.     If Len(Trim(sBathQuery)) = 0 Then Exit Function
  641.     
  642.     Dim lArray()            As String
  643.     Dim lMax                As Long
  644.     
  645.     If (IsConnected) Then
  646.         lArray = SQLParse(sBathQuery)
  647.         lMax = UBound(lArray)
  648.         
  649.         For i = 0 To UBound(lArray)
  650.             lRet = mysql_real_query(APIHandle, StrPtr(StrConv(lArray(i), vbFromUnicode)), Len(lArray(i)))
  651.             If lRet <> 0 Then
  652.                 If (GiveError) Then
  653.                     Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  654.                 Else
  655.                     RaiseErrorEvent
  656.                 End If
  657.                 Exit Function
  658.             End If
  659.             DoEvents
  660.             RaiseEvent BatchQueryProgress(lMax, i, RESOURCE_PROGRESS)
  661.         Next i
  662.         
  663.         BathRealQueryFromResource = True
  664.         Erase lArray
  665.     Else
  666.         If (mGiveError) Then
  667.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  668.         Else
  669.             RaiseErrorEvent -3
  670.         End If
  671.     End If
  672. End Function
  673.  
  674. Public Function SendQuery(ByVal sQuery As String) As Boolean
  675.    
  676.     If Len(Trim(sQuery)) = 0 Then Exit Function
  677.     
  678.     If (IsConnected) Then
  679.         lRet = mysql_send_query(APIHandle, StrPtr(StrConv(sQuery, vbFromUnicode)), Len(sQuery))
  680.         If lRet = 0 Then
  681.             SendQuery = True
  682.         Else
  683.             SendQuery = False
  684.             If (GiveError) Then
  685.                 Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  686.             Else
  687.                 RaiseErrorEvent
  688.             End If
  689.         End If
  690.     Else
  691.         If (mGiveError) Then
  692.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  693.         Else
  694.             RaiseErrorEvent -3
  695.         End If
  696.     End If
  697. End Function
  698.  
  699. Public Function DatabaseExists(ByVal sDatabaseName As String) As Boolean
  700.     If Len(Trim(sDatabaseName)) = 0 Then Exit Function
  701.     
  702.     Dim lName                   As Long
  703.     
  704.     If (IsConnected) Then
  705.         
  706.         
  707.         lResult = mysql_list_dbs(APIHandle, StrPtr(StrConv(vbNullString, vbFromUnicode)))
  708.         If lResult Then
  709.             For i = 1 To mysql_num_rows(lResult)
  710.                 lRet = mysql_fetch_row(lResult)
  711.                 If lRet Then
  712.                     CopyMemory lName, ByVal lRet, SIZE_OF_CHAR * 1
  713.                     If lstrcmpi(lName, sDatabaseName) = 0 Then
  714.                         DatabaseExists = True
  715.                         Exit For
  716.                     End If
  717.                 End If
  718.             Next i
  719.             lRet = mysql_free_result(lResult)
  720.         End If
  721.     Else
  722.         If (mGiveError) Then
  723.             Err.Raise vbObjectError - 3, , "-3:" & " Aktif ba≡lant² yok."
  724.         Else
  725.             RaiseErrorEvent -3
  726.         End If
  727.     End If
  728. End Function
  729.  
  730. Public Function ListDatabases() As Long
  731.     If (IsConnected) Then
  732.         lResult = mysql_list_dbs(APIHandle, StrPtr(StrConv(vbNullString, vbFromUnicode)))
  733.         If lResult Then
  734.             ListDatabases = lResult
  735.         Else
  736.             If (GiveError) Then
  737.                 Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  738.             Else
  739.                 RaiseErrorEvent
  740.             End If
  741.         End If
  742.     Else
  743.         RaiseErrorEvent -3
  744.     End If
  745. End Function
  746.  
  747. Public Function TableExists(ByVal sDatabaseName As String, ByVal sTableName As String) As Boolean
  748.     If Len(Trim(sDatabaseName)) = 0 Then Exit Function
  749.     If Len(Trim(sTableName)) = 0 Then Exit Function
  750.  
  751.     If DatabaseExists(sDatabaseName) Then
  752.         SelectDatabase sDatabaseName
  753.     Else
  754.         TableExists = False
  755.         RaiseErrorEvent -6
  756.         Exit Function
  757.     End If
  758.  
  759.     lResult = mysql_list_tables(APIHandle, StrPtr(StrConv(sTableName, vbFromUnicode)))
  760.     If lResult Then
  761.         TableExists = Not (mysql_num_rows(lResult) = 0)
  762.         lRet = mysql_free_result(lResult)
  763.     Else
  764.         If (GiveError) Then
  765.             Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  766.         Else
  767.             RaiseErrorEvent
  768.         End If
  769.     End If
  770. End Function
  771.  
  772. Public Function ListTables(ByVal sDatabaseName As String) As Long
  773.     If Len(Trim(sDatabaseName)) = 0 Then Exit Function
  774.  
  775.     If DatabaseExists(sDatabaseName) Then
  776.         SelectDatabase sDatabaseName
  777.     Else
  778.         RaiseErrorEvent -6
  779.         Exit Function
  780.     End If
  781.  
  782.     lResult = mysql_list_tables(APIHandle, StrPtr(StrConv(vbNullString, vbFromUnicode)))
  783.     If lResult Then
  784.         ListTables = lResult
  785.     Else
  786.         If (GiveError) Then
  787.             Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  788.         Else
  789.             RaiseErrorEvent
  790.         End If
  791.     End If
  792. End Function
  793.  
  794. Public Function EscapeString(ByVal sString As String) As String
  795.     Dim sTmp            As String
  796.     Dim sLen            As Long
  797.  
  798.     sLen = Len(sString)
  799.     sTmp = Space(sLen * 2 + 1)
  800.  
  801.     sLen = mysql_escape_string(sTmp, sString, sLen)
  802.     EscapeString = Left(sTmp, sLen)
  803. End Function
  804.  
  805. Public Function FieldExists(ByVal sDatabaseName As String, _
  806.                             ByVal sTableName As String, _
  807.                             ByVal sFieldName As String) As Boolean
  808.  
  809.     If Len(Trim(sDatabaseName)) = 0 Then Exit Function
  810.     If Len(Trim(sTableName)) = 0 Then Exit Function
  811.     If Len(Trim(sFieldName)) = 0 Then Exit Function
  812.  
  813.     If TableExists(sDatabaseName, sTableName) Then
  814.         SelectDatabase sDatabaseName
  815.     Else
  816.         FieldExists = False
  817.         RaiseErrorEvent -7
  818.         Exit Function
  819.     End If
  820.  
  821.     lResult = mysql_list_fields(APIHandle, StrPtr(StrConv(sTableName, vbFromUnicode)), StrPtr(StrConv(sFieldName, vbFromUnicode)))
  822.     If lResult Then
  823.         FieldExists = (mysql_num_rows(lResult) = 0)
  824.         lRet = mysql_free_result(lResult)
  825.     Else
  826.         If (GiveError) Then
  827.             Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  828.         Else
  829.             RaiseErrorEvent
  830.         End If
  831.     End If
  832. End Function
  833.  
  834. Public Function ListFields(ByVal sDatabaseName As String, ByVal sTableName As String) As Long
  835.     If Len(Trim(sDatabaseName)) = 0 Then Exit Function
  836.     If Len(Trim(sTableName)) = 0 Then Exit Function
  837.     
  838.     If TableExists(sDatabaseName, sTableName) Then
  839.         SelectDatabase sDatabaseName
  840.     Else
  841.         RaiseErrorEvent -7
  842.         Exit Function
  843.     End If
  844.  
  845.     lResult = mysql_list_fields(APIHandle, StrPtr(StrConv(sTableName, vbFromUnicode)), StrPtr(StrConv(vbNullString, vbFromUnicode)))
  846.     If lResult Then
  847.         ListFields = lResult
  848.     Else
  849.         If (GiveError) Then
  850.             Err.Raise vbObjectError + GetErrorCode, , GetErrorCode & ": " & GetErrorDescription
  851.         Else
  852.             RaiseErrorEvent
  853.         End If
  854.     End If
  855. End Function
  856.  
  857. Public Sub FreeResult(ByVal ResultPointer As Long)
  858.     lRet = mysql_free_result(ResultPointer)
  859. End Sub
  860.  
  861. Public Function Disconnect() As Boolean
  862.     If (IsConnected) Then
  863.         lRet = mysql_close(APIHandle)
  864.         IsConnected = False
  865.         Disconnect = True
  866.         RaiseEvent Disconnected(APIHandle, mServerAddress)
  867.         APIHandle = 0
  868.         lRet = 0
  869.         bRet = False
  870.     Else
  871.         Disconnect = False
  872.         RaiseEvent OnError(-3, " Aktif ba≡lant² yok.")
  873.     End If
  874. End Function
  875.  
  876. Private Function GetErrorCode() As Long
  877.     GetErrorCode = mysql_errno(APIHandle)
  878. End Function
  879.  
  880. Private Function GetErrorDescription() As String
  881.     GetErrorDescription = Ptr2Str(mysql_error(APIHandle))
  882. End Function
  883.  
  884. Public Function Ptr2Str(ByVal lPtr As Long) As String
  885.     On Local Error Resume Next
  886.  
  887.     Dim lTmp As Long
  888.  
  889.     If lPtr = 0 Then Exit Function
  890.  
  891.     Dim bTmp As Byte
  892.     Dim aBytes() As Byte
  893.     Dim lChars As Long
  894.  
  895.     lChars = lstrlen(lPtr)
  896.     If lChars = 0 Then Exit Function
  897.  
  898.     ReDim aBytes(1 To lChars) As Byte
  899.     aBytes = String(lChars, " ")
  900.     CopyMemory aBytes(1), ByVal (lPtr), lChars
  901.     Ptr2Str = StrConv(aBytes, vbUnicode)
  902.  
  903.     lTmp = InStr(Ptr2Str, vbNullChar)
  904.     If lTmp > 0 Then
  905.         Ptr2Str = Trim(Left$(Ptr2Str, lTmp - 1))
  906.     Else
  907.         Ptr2Str = Ptr2Str
  908.     End If
  909.  
  910.     Erase aBytes
  911. End Function
  912.  
  913. Private Sub Class_Initialize()
  914.     mUsername = "root"
  915.     mPassword = ""
  916.     mServerAddress = "localhost"
  917.     mServerPort = 3306
  918.     mDatabaseName = ""
  919.     mUnixSocket = ""
  920.     mConnectionTimeout = 15
  921.     mCharset = "latin5"
  922.     mGiveError = True
  923. End Sub
  924.  
  925. Private Sub Class_Terminate()
  926.     bRet = Disconnect
  927. End Sub
  928.  
  929. Public Sub ConvertADORS(ByVal ResultPointer As Long, ByRef RSObject As Object)
  930.     Dim FieldCount              As Long
  931.     Dim RowCount                As Long
  932.     Dim FieldNames()            As Long
  933.  
  934.     Dim FieldName               As Long
  935.     Dim FieldLenght             As Long
  936.     Dim FieldType               As Long
  937.  
  938.     Dim BlobIndex               As Long
  939.  
  940.     FieldCount = mysql_field_count(APIHandle)
  941.     RowCount = mysql_num_rows(ResultPointer)
  942.     ReDim FieldNames(1 To FieldCount) As Long
  943.  
  944.     Dim sl As Long
  945.     With RSObject
  946.  
  947.         For i = 1 To FieldCount
  948.             lRet = mysql_fetch_field(ResultPointer)
  949.             If lRet Then
  950.                 CopyMemory FieldName, ByVal lRet, 4
  951.                 CopyMemory FieldLenght, ByVal lRet + 28, 4
  952.                 CopyMemory FieldType, ByVal lRet + 76, 4
  953.                 
  954.                 If FieldType = 252 Then
  955.                     .Fields.Append Ptr2Str(FieldName), 12, 65535
  956.                     BlobIndex = i
  957.                 ElseIf FieldType = 246 Then 'Is Decimal Field To adBSTR
  958.                     .Fields.Append Ptr2Str(FieldName), 8, 127
  959.                 Else
  960.                     .Fields.Append Ptr2Str(FieldName), MyFieldTypeToADOFieldType(FieldType), FieldLenght + 1, 32
  961.                 End If
  962.             End If
  963.         Next i
  964.  
  965.         .Open
  966.  
  967.         For i = 1 To RowCount
  968.             lRet = mysql_fetch_row(ResultPointer)
  969.             If lRet Then
  970.                 CopyMemory FieldNames(1), ByVal lRet, SIZE_OF_CHAR * FieldCount
  971.                 .AddNew
  972.                  For j = 1 To FieldCount
  973.                     If .Fields(j - 1).Type <> 7 Then
  974.                         If j = BlobIndex Then 'Is Blob Field
  975.                             Dim DataLength          As Long
  976.                             Dim Data()              As Byte
  977.                             
  978.                             CopyMemory DataLength, ByVal mysql_fetch_lengths(ResultPointer), IIf((BlobIndex - 1) = 0, 1, BlobIndex - 1) * SIZE_OF_CHAR
  979.                             
  980.                             ReDim Data(DataLength) As Byte
  981.                             
  982.                             CopyMemory Data(0), ByVal FieldNames(j), DataLength
  983.  
  984.                             .Fields(j - 1) = Data
  985.                             Erase Data
  986.                         Else
  987.                             .Fields(j - 1) = Ptr2Str(FieldNames(j))
  988.                         End If
  989.                     Else
  990.                         Dim sTmp As String
  991.                         sTmp = Ptr2Str(FieldNames(j))
  992.                         If Len(Trim(sTmp)) > 1 Then
  993.                         .Fields(j - 1) = DateSerial(CInt(Left(sTmp, 4)), CInt(Mid(sTmp, 6, 2)), CInt(Right(sTmp, 2)))
  994.                             Else
  995.                         .Fields(j - 1) = Null
  996.                         End If
  997.                     End If
  998.                  Next j
  999.             End If
  1000.         Next i
  1001.         .UpdateBatch 4
  1002.     End With
  1003.  
  1004.     Erase FieldNames
  1005.  
  1006.     If Not (RSObject.EOF And RSObject.BOF) Then RSObject.MoveFirst
  1007.     Call Me.FreeResult(ResultPointer)
  1008. End Sub
  1009.  
  1010. Private Function MyFieldTypeToADOFieldType(ByVal MyField As Long) As Long
  1011.     Select Case MyField
  1012.         Case 3
  1013.             MyFieldTypeToADOFieldType = 20
  1014.         Case 8
  1015.             MyFieldTypeToADOFieldType = 20
  1016.         Case 254
  1017.             MyFieldTypeToADOFieldType = 129
  1018.         Case 4
  1019.             MyFieldTypeToADOFieldType = 6
  1020.         Case 10
  1021.             MyFieldTypeToADOFieldType = 7
  1022.         Case 11
  1023.             MyFieldTypeToADOFieldType = 8
  1024.         Case 7
  1025.             MyFieldTypeToADOFieldType = 135
  1026.         Case 0, 246
  1027.             MyFieldTypeToADOFieldType = 14
  1028.         Case 5
  1029.             MyFieldTypeToADOFieldType = 5
  1030.         Case 6
  1031.             MyFieldTypeToADOFieldType = 0
  1032.         Case 9
  1033.             MyFieldTypeToADOFieldType = 3
  1034.         Case 2
  1035.             MyFieldTypeToADOFieldType = 2
  1036.         Case 1
  1037.             MyFieldTypeToADOFieldType = 16
  1038.         Case 253
  1039.             MyFieldTypeToADOFieldType = 200
  1040.         Case 255, 252, 250, 251, 248, 247, 16, 14
  1041.             MyFieldTypeToADOFieldType = 12
  1042.         End Select
  1043. End Function
  1044.  
  1045. Private Sub RaiseErrorEvent(Optional ByVal lErrorCode As Long = -21565)
  1046.     Select Case lErrorCode
  1047.         Case -21565
  1048.             RaiseEvent OnError(GetErrorCode, GetErrorDescription)
  1049.         Case -1
  1050.             RaiseEvent OnError(lErrorCode, "MySQL API Arabirimi ba■lat²lamad².")
  1051.         Case -2
  1052.             RaiseEvent OnError(lErrorCode, "Dosya bulunamad².")
  1053.         Case -3
  1054.             RaiseEvent OnError(lErrorCode, "Aktif ba≡lant² yok.")
  1055.         Case -4
  1056.             RaiseEvent OnError(lErrorCode, "Aktif ba≡lant² var. ╓ncelikle aktif ba≡lant²y² kapatman²z gerekir.")
  1057.         Case -5
  1058.             RaiseEvent OnError(lErrorCode, "Veritaban² sunucu versiyonu 5.0'dan dⁿ■ⁿk oldu≡u iτin 'SET NAMES' komutu i■letilemiyor. Lⁿtfen sunucu versiyonunuzu gⁿncelleyiniz.")
  1059.         Case -6
  1060.             RaiseEvent OnError(lErrorCode, "Veritaban² Bulunamad²!")
  1061.         Case -7
  1062.             RaiseEvent OnError(lErrorCode, "Tablo Bulunamad²!")
  1063.     End Select
  1064. End Sub
  1065.  
  1066. Private Function SQLParse(ByVal sText As String) As String()
  1067.     Dim Dizi()              As String
  1068.     Dim dC                  As Long
  1069.     Dim SrcStr              As String
  1070.     Dim LastPos             As Long
  1071.     Dim Flag                As Boolean
  1072.     Dim i                   As Long
  1073.     
  1074.     dC = -1
  1075.     LastPos = 1
  1076.     SrcStr = sText
  1077.     Flag = True
  1078.     
  1079.     For i = 1 To Len(SrcStr)
  1080.         If InStr(1, Mid(SrcStr, i, 5), "BEGIN") Then
  1081.             Flag = False
  1082.         End If
  1083.         If InStr(1, Mid(SrcStr, i, 4), "END;") Then
  1084.             Flag = True
  1085.         End If
  1086.         If Mid(SrcStr, i, 1) = "'" Then
  1087.             If Mid(SrcStr, i - 1, 1) <> "\" Then
  1088.                 Flag = Not Flag
  1089.             End If
  1090.         End If
  1091.         
  1092.         If Flag Then
  1093.             If Mid(SrcStr, i, 1) = ";" Then
  1094.                 i = i + 1
  1095.                 dC = dC + 1
  1096.                 ReDim Preserve Dizi(dC) As String
  1097.                 Dizi(dC) = Mid(SrcStr, LastPos, i - LastPos)
  1098.                 Dizi(dC) = SqlTemizle(Dizi(dC))
  1099.                 LastPos = i
  1100.             End If
  1101.         End If
  1102.     Next i
  1103.     SQLParse = Dizi()
  1104. End Function
  1105.  
  1106. Private Function SqlTemizle(ByVal sText As String) As String
  1107.     Dim i                   As Long
  1108.     Dim Dizi()              As String
  1109.     
  1110.     If InStr(1, sText, vbCrLf) Then
  1111.         Dizi = Split(sText, vbCrLf)
  1112.         For i = 0 To UBound(Dizi)
  1113.             If Left(Dizi(i), 1) = "#" Then
  1114.                 Dizi(i) = ""
  1115.             End If
  1116.         Next i
  1117.     
  1118.         SqlTemizle = Join(Dizi, vbCrLf)
  1119.         SqlTemizle = Replace(SqlTemizle, vbCrLf & vbCrLf, "")
  1120.         If Left(SqlTemizle, 2) = vbCrLf Then
  1121.             SqlTemizle = Right(SqlTemizle, Len(SqlTemizle) - 2)
  1122.         End If
  1123.         If Right(SqlTemizle, 2) = vbCrLf Then
  1124.             SqlTemizle = Left(SqlTemizle, Len(SqlTemizle) - 2)
  1125.         End If
  1126.     Else
  1127.         SqlTemizle = sText
  1128.     End If
  1129.     SqlTemizle = Trim(SqlTemizle)
  1130. End Function
  1131.  
  1132.  
  1133.  
  1134.  
  1135.